/**
 * 动作创建函数，返回一个动作对象的函数。
 *
 *    作用：
 *      就是复用
 */

import { INCREMENT, DECREMENT, CHANGEMSG } from "./actionTypes";

// 版本一：普通的动作创建函数
export const increment = () => ({ type: INCREMENT });
export const decrement = () => ({ type: DECREMENT });
export const changeMsg = (payload?: string) => ({ type: CHANGEMSG, payload });

// 版本二：携带有 dispatch 的动作创建函数
export const incrementTwo = (dispatch) => dispatch(increment());
export const decrementTwo = (dispatch) => dispatch(decrement());
export const changeMsgTwo = (dispatch, payload?: string) =>
  dispatch(changeMsg(payload));
